import pytest, time
from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.Pageobject.system_setting_page import SystemSettingPage
from Case.python_ui.Pageobject.login_pages import Loginpages
from Case.python_ui.Test_data.login_data import Logindata
from selenium import webdriver
from Case.python_ui.PageLocate.admin_dashboards_page_locator import AdminDashboardsPageLocator
from Case.python_ui.PageLocate.admin_exporting_record_locator import AdminExportingRecordLocator
from selenium.common.exceptions import NoSuchElementException


class AdminDashboardsPageModule(Basepage):

    # 判断是否包含元素
    def check_contain_str(self, string, except_string):
        if except_string in string:
            assert True
        else:
            assert False, '实际值:' + string + '期望值:' + except_string

    # 校验某个属性值是否符合预期
    def check_attribute(self, real_result, except_result):
        if real_result == except_result:
            assert True
        else:
            assert False, '实际值:' + real_result + '期望值:' + except_result

    # 元素是否存在
    def element_is_exist(self, locate):
        doc = '判断元素是否存在'
        try:
            self.get_element(locate, doc)
        except NoSuchElementException as e:
            return False
        else:
            return True

    # 进入Dashboard-Orders菜单界面
    def enter_dashboards_orders(self):
        time.sleep(2)
        doc = "进入Dashboard-Orders菜单界面"
        for i in range(3):
            try:
                eles = self.get_elements(AdminDashboardsPageLocator.default_page_expanded, doc)
                for ele in eles:
                    ele.click()
                    time.sleep(1)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_tittle, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_orders_tittle, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_page, doc)

    # 查看Orders界面订单报表默认页面订单类型维度
    def check_dashboards_orders_type_func(self):
        time.sleep(5)
        doc = "查看Orders界面订单报表默认页面订单类型维度"
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_page_tittle, doc)
        # 点击切换到by order type标签页
        self.move_mouse_to_click_element(AdminDashboardsPageLocator.dashboards_orders_order_type_tab, doc)
        time.sleep(3)
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_cumulative_data_tracking_tittle, doc)
        # self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_page_tittle, doc).text, 'Orders')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_order_type_tab, doc).text, 'By Order Type')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_cumulative_data_tracking_tittle, doc).text,  'Cumulative Data Tracking')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_total_orders_tittle, doc).text,  'Total Orders')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_daily_data_tracking_tittle, doc).text,  'Daily Data Tracking')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_daily_data_trend_tittle, doc).text, 'Daily Data Trend')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_orders_daily_data_distribution_tittle, doc).text, 'Daily Data Distribution')

    # 查看Orders界面daily data tracking模块数据
    def check_orders_daily_data_tracking(self):
        time.sleep(5)
        doc = "查看Orders界面daily data tracking模块数据"
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_page_tittle, doc)
        # 点击切换到by order type标签页
        self.move_mouse_to_click_element(AdminDashboardsPageLocator.dashboards_orders_order_type_tab, doc)
        time.sleep(3)
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_orders_cumulative_data_tracking_tittle, doc)
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_total_orders_field, doc).text, 'Total Orders')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_new_field, doc).text, 'New')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_release_field, doc).text, 'Release')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_modify_field, doc).text, 'Modify')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_renew_field, doc).text, 'Renew')

    # 查看Orders页面的筛选器内容
    def check_orders_filter_data(self):
        time.sleep(3)
        doc = "查看Orders页面的筛选器内容"
        self.move_mouse_to_click_element(AdminDashboardsPageLocator.orders_settings_btn, doc)
        self.wait_elevisble(AdminDashboardsPageLocator.orders_settings_daily_email_field, doc)
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_settings_daily_email_field, doc).text, 'Daily Email')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_settings_filter_field, doc).text, 'Filter')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_settings_region_field, doc).text, 'Region')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_settings_zone_field, doc).text, 'Zone')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.orders_settings_computing_field, doc).text, 'Computing')

    # 进入Dashboard-Sale Amount菜单界面
    def enter_dashboards_sale_amount(self):
        time.sleep(2)
        doc = "进入Dashboard-Sale Amount菜单界面"
        for i in range(3):
            try:
                eles = self.get_elements(AdminDashboardsPageLocator.default_page_expanded, doc)
                for ele in eles:
                    ele.click()
                    time.sleep(1)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_sales_amount_tittle, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_sales_amount_tittle, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_sales_amount_page, doc)

    # 查看Sale Amount页面的筛选器内容
    def check_sale_amount_filter_data(self):
        time.sleep(5)
        doc = "查看Sale Amount页面的筛选器内容"
        self.move_mouse_to_click_element(AdminDashboardsPageLocator.sales_amount_settings_btn, doc)
        self.wait_elevisble(AdminDashboardsPageLocator.settings_daily_email_field, doc)
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_daily_email_field, doc).text, 'Daily Email')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_displayed_currency_field, doc).text, 'Displayed Currency:')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_filter_field, doc).text, 'Filter')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_currency_field, doc).text, 'Currency')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_region_field, doc).text, 'Region')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_zone_field, doc).text, 'Zone')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.settings_computing_field, doc).text, 'Computing')

    # 进入Dashboard-Users Status菜单界面
    def enter_dashboards_users_status(self):
        time.sleep(2)
        doc = "进入Dashboard-Users Status菜单界面"
        for i in range(3):
            try:
                eles = self.get_elements(AdminDashboardsPageLocator.default_page_expanded, doc)
                for ele in eles:
                    ele.click()
                    time.sleep(1)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_tab, doc)
                self.wait_elevisble(AdminDashboardsPageLocator.dashboards_user_status_tittle, doc)
                self.click_element(AdminDashboardsPageLocator.dashboards_user_status_tittle, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_user_status_page, doc)

    # 查看Users Status界面订单报表默认页面
    def check_dashboards_users_status_data_func(self):
        time.sleep(5)
        doc = "查看Orders界面订单报表默认页面订单类型维度"
        self.wait_elevisble(AdminDashboardsPageLocator.dashboards_user_status_page, doc)
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_active_tab, doc).text, 'Active')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_dunning_tab, doc).text, 'Dunning')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_active_data_tittle, doc).text, 'Active Data')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_dau_mau_tittle, doc).text, 'DAU/MAU')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_time_spent_tittle, doc).text,  'Top 10 Users by Time Spent on CRE')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_daily_data_trend_tittle, doc).text, 'Daily Data Trend')
        self.check_attribute(self.get_element(AdminDashboardsPageLocator.dashboards_users_status_daily_data_tracking_tittle, doc).text, 'Daily Data Tracking')






